//
//  PlacemanagerViewController.m
//  ZhaiJuBao
//
//  Created by YuanZhiPu on 15/12/31.
//  Copyright © 2015年 NeiQuan. All rights reserved.
//

#import "PlacemanagerViewController.h"
#import "XRCommonCityPickerView.h"
@interface PlacemanagerViewController ()

@end

@implementation PlacemanagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *right=[UIButton buttonWithType:UIButtonTypeCustom];
    [right setFrame:CGRectMake(0, 0, 50, 30)];
    [right setTitle:@"保存" forState:UIControlStateNormal];
    right.titleLabel.font=[UIFont systemFontOfSize:15];
    [right setTitleColor:[ UIColor whiteColor] forState:UIControlStateNormal];
    
    [right addTarget:self action:@selector(clickrightButton:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem=[[ UIBarButtonItem alloc] initWithCustomView:right];
        self.title = @"添加新地址";
    
    _flag=0;
    [_switBtn setOn:NO animated:YES];
     [_switBtn addTarget:self action:@selector(getValue1:) forControlEvents:UIControlEventValueChanged];
}
-(void)getValue1:(id)sender{
    UISwitch *swi2=(UISwitch *)sender;
    
    if (swi2.isOn) {
        
        NSLog(@"打开");
        _flag=1;
    }else{
        
        NSLog(@"关上");
        _flag=0;
        
    }
}

- (IBAction)chooseCityButtonClick:(UIButton *)sender {
   
    [_phoneTF endEditing:YES];
    XRCommonCityPickerView  *pickerView=[[XRCommonCityPickerView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    //这里更新地址
    [pickerView popCityPickerViewWithClickBlock:^(Provice *provice, City *city, Region *region){
        _zipCodeTF.text=[NSString stringWithFormat:@"%@%@%@",provice.name,city.name,region.name];
        
    }];
    [[UIApplication sharedApplication].keyWindow addSubview:pickerView];

}
#pragma mark - 保存按钮
-(void)clickrightButton:(UIButton*)btn
{
//    //需要正则匹配
//    [self.view endEditing:YES];
//    if ([NSString StringIsNULL:_nameTF.text])
//    {
//        [self showMBErrorMessage:@"请输入收货人姓名" inView:self.view];
//        return;
//    }else if ([NSString StringIsNULL:_phoneTF.text])
//    {
//        [self showMBErrorMessage:@"请输入联系电话" inView:self.view];
//        return;
//    }else if (![NSString isMobileNumber:_phoneTF.text])
//    {   [_phoneTF shake];
//        [self showMBErrorMessage:@"手机号码格式错误" inView:self.view];
//        return;
//    }if ([NSString StringIsNULL:_zipCodeTF.text])
//    {
//        [self showMBErrorMessage:@"请选择地区" inView:self.view];
//        return;
//    }if ([NSString StringIsNULL:_cityTF.text])
//    {
//        [self showMBErrorMessage:@"请输入详细地址" inView:self.view];
//        return;
//    }
//    if (_nameTF.text.length!=0&&_phoneTF.text.length!=0&&_zipCodeTF.text.length!=0&&_cityTF.text.length!=0){
//        _zipCodeTF.text = [_zipCodeTF.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//     
//        
//    }else
//    {
//        [self showMBErrorMessage:@"请将信息填写完整" inView:self.view];
//    }
    
}


@end
